# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/28 下午4:04
 @Author  : tgy
 
"""
from collections.abc import Iterable


def chain(*args):
    ...
    for arg in args:
        ...
        if not isinstance(arg,Iterable):
            raise TypeError('must iterable')
        yield from arg


def extand(args):
    ...
    for arg in args:
        ...
        if isinstance(arg, Iterable):
            ...
            yield from extand(arg)
        else:
            yield arg


class Person:
    __slots__ = ['name', 'children']

    def __init__(self,name):
        self.name = name
        self.children = []

    def add_child(self,child):
        self.children.append(child)

    def __str__(self):
        return 'name {}'.format(self.name)

    def __iter__(self):
        return iter(self.children)

    def deep_first(self):
        ...
        yield self
        for child in self:
            yield from child.deep_first()







if __name__ == '__main__':
    ...
    # for val in chain([1,2,3],'abc'):
    #     print(val)

    # for val in extand((1,[1,2,3],(4,5,6))):
    #     print(val)
    per = Person('zhangsan')
    per.add_child(Person('lisi'))
    per.add_child(Person('wangwu'))

    for p in per.deep_first():
        print(p)

    it = iter([1,2,3,4])

    for val in iter(lambda :next(it),3):
        print(val)

